Skip to content

fix: safely append beta query for anthropic target URLs #672

Closed
gopkg-dev wants to merge 3 commits intoWei-Shaw:mainfrom
gopkg-dev:copilot/fix-target-url-parameter
Closed

fix: safely append beta query for anthropic target URLs #672
gopkg-dev wants to merge 3 commits intoWei-Shaw:mainfrom
gopkg-dev:copilot/fix-target-url-parameter

Conversation

@gopkg-dev
Copy link

This pull request updates the way our gateway service constructs upstream Anthropic API URLs to ensure the beta=true query parameter is always present, regardless of the endpoint or existing query parameters. This change centralizes and standardizes URL construction, reducing the risk of missing or malformed beta flags. Relevant tests have also been updated to verify the new URL structure.

URL construction improvements:

  • Added a new helper function buildAnthropicTargetURL in gateway_service.go to append or set the beta=true query parameter correctly for all Anthropic API requests, handling cases where the endpoint already has query parameters.
  • Updated all Anthropic upstream request builders (buildUpstreamRequestAnthropicAPIKeyPassthrough, buildUpstreamRequest, buildCountTokensRequestAnthropicAPIKeyPassthrough, buildCountTokensRequest) to use the new helper for constructing URLs. [1] [2] [3] [4]
  • Added the necessary import for net/url to support the new URL construction logic.

Test updates:

  • Enhanced tests to assert that requests to Anthropic endpoints now include the correct beta=true query parameter. [1] [2]

Copilot AI and others added 3 commits February 27, 2026 17:46
Co-authored-by: gopkg-dev <58848833+gopkg-dev@users.noreply.github.com>
Co-authored-by: gopkg-dev <58848833+gopkg-dev@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 27, 2026 18:03
@gopkg-dev gopkg-dev changed the title Preserve and safely append beta query for custom Anthropics URLs fix: safely append beta query for anthropic target URLs Feb 27, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the gateway’s Anthropic upstream URL construction so beta=true is consistently present when targeting custom Anthropic base URLs, and adjusts passthrough tests to assert the new URL shape.

Changes:

  • Added buildAnthropicTargetURL helper to append/set beta=true via URL parsing.
  • Updated Anthropic upstream request builders to use the new helper for /v1/messages and /v1/messages/count_tokens.
  • Updated API-key passthrough tests to assert beta=true appears in the upstream request URI.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
backend/internal/service/gateway_service.go Introduces centralized Anthropic target URL builder and switches request builders to use it.
backend/internal/service/gateway_anthropic_apikey_passthrough_test.go Adds assertions that upstream requests include beta=true in the URI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gopkg-dev gopkg-dev closed this by deleting the head repository Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants